using SharePoint.Security.ConfigAnalyzer.Engine.Base;
using SharePoint.Security.ConfigAnalyzer.Engine.Common;
using Microsoft.SharePoint.Administration;

namespace SharePoint.Security.ConfigAnalyzer.Engine.Rules.Others
{
    public class CentralAdminSiteOnSSL : BaseRule
    {
        public CentralAdminSiteOnSSL()
        {
            RuleInfo = new RuleInfo
                           {
                               Title = "Central Admin site must be on SSL (HTTPS)",
                               Description = "Central Admin site must be on SSL (HTTPS)",
                               ExpectedValue = "Should be on HTTPS"
                           };
        }

        #region Overrides of BaseRule

        public override void Validate()
        {
            SPAdministrationWebApplication caWebApp = ObjectHelper.SPAdministrationWeb;

            var url = caWebApp.Sites[0].Url;

            if (url.StartsWith("https://") || url.StartsWith("HTTPS://"))
            {
                Status = Status.Pass;
            }
            else
            {
                Status = Status.Fail;
            }

            CurrentValue = string.Format("Admin URL is {0}", url);
        }

        #endregion
    }
}